/**
 * 977. 有序数组的平方
 * @param {number[]} nums
 * @return {number[]}
 */
var sortedSquares = function (nums) {
	return nums.map((num) => num * num).sort((a, b) => a - b)
}
var sortedSquares = function (nums) {
	const n = nums.length
	const ans = new Array(n)
	let i = 0,
		j = n - 1,
		pos = n - 1

	while (i <= j) {
		if (nums[i] * nums[i] > nums[j] * nums[j]) {
			ans[pos] = nums[i] * nums[i]
			++i
		} else {
			ans[pos] = nums[j] * nums[j]
			--j
		}
		--pos
	}
	return ans
}
const res = sortedSquares([-4, -1, 0, 3])
console.log(res)
